{extend name="../../../view/public/base" /}

{block name="css"}
<style>
    body {
        background-color: #F2F2F2;
    }
</style>
{/block}

{block name="body"}
<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card" style="padding: 10px">
                <form class="layui-form" lay-filter="addForm" autocomplete="off">
                    <!--服务ID-->
                    <div class="layui-form-item layui-hide">
                        <label class="layui-form-label">服务ID</label>
                        <div class="layui-input-block">
                            <input type="number" name="service_id" placeholder="请输入服务ID" class="layui-input" value="{$row.service_id}">
                        </div>
                    </div>
                    <!--次数-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">次数</label>
                        <div class="layui-input-block">
                            <input type="number" name="amount" placeholder="请输入次数" class="layui-input" value="{$row.amount}">
                        </div>
                    </div>
                    <!--价格-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">价格</label>
                        <div class="layui-input-block">
                            <input type="number" name="price" placeholder="请输入价格" class="layui-input" value="{$row.price}">
                        </div>
                    </div>
                    <!--有效天数-->
                    <div class="layui-form-item layui-hide">
                        <label class="layui-form-label">有效天数</label>
                        <div class="layui-input-block">
                            <input type="number" name="days" placeholder="请输入有效天数" class="layui-input" value="{$row.days}">
                        </div>
                    </div>
                    <!--删除时间-->
                    <!--<div class="layui-form-item">
                        <label class="layui-form-label">删除时间</label>
                        <div class="layui-input-inline">
                            <input id='delet_time'  type='text' name='delet_time' placeholder='请输入删除时间' class='layui-input'>
                            &lt;!&ndash;格式化时间&ndash;&gt;
                            <script>
                                formatDate("{$row.delet_time}", 'delet_time')
                            </script>                            
                        </div>
                    </div>-->

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submitBtn">立即提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"}
<script>
    var layer, form, bwajax, upload, $, laydate;

    layui.use(['layer', 'form', 'bwajax', 'upload', 'laydate'], function () {
        layer = layui.layer;
        form = layui.form;
        bwajax = layui.bwajax.instance();
        upload = layui.upload;
        $ = layui.jquery;
        laydate = layui.laydate;

        //删除时间 日期时间选择器
        laydate.render({
            elem: '#delet_time'
            ,type: 'datetime'
        });


        //监听提交按钮
        form.on('submit(submitBtn)', function (obj) {
            data = obj.field;

            if(!data.service_id) {layer.msg('服务ID不能为空', {icon: 2});return false}
            if(!data.amount) {layer.msg('次数不能为空', {icon: 2});return false}
            if(!data.price) {layer.msg('价格不能为空', {icon: 2});return false}
            if(!data.days) {layer.msg('有效天数不能为空', {icon: 2});return false}
            //时间转为时间戳
            // data.delet_time = Date.parse(data.delet_time) / 1000;


            //ajax调用后台接口
            bwajax.post("{:Url('/manage/admin/cloud/packet/edit')}?id={$row.id}", data)
                .then(function (response) {
                    if (response.data.data.errcode === 0) {
                        layer.msg('提交成功', {icon: 1});
                        submitSuccess();
                    } else {
                        layer.msg(response.data.msg, {icon: 2});
                    }
                })

            return false;
        })
    });
</script>
{/block}